<?php

@include_once("connect.php");

$res = [];
$Ntell = $_POST['Ntellnumber'];
$tell = $_POST['tellnumber'];
$pwd = $_POST['password'];
$name = $_POST['username'];
$val;


if ($Ntell) {
  $val = $Ntell;

  //判断新电话是否被注册
  $sql_c = "SELECT * FROM user WHERE tellnumber='$tell'";
  $c = mysqli_query($con, $sql_c);
  $arr= mysqli_fetch_array($c);

  $sql_a = "UPDATE user SET tellnumber=$Ntell WHERE tellnumber='$tell'";
  $sql_b = "UPDATE user_cart SET tellnumber=$Ntell WHERE tellnumber='$tell'";
}
if ($pwd) {
  $val = $pwd;
  $sql_a = "UPDATE user SET password='$pwd' WHERE tellnumber='$tell'";
}
if ($name) {
  $val = $name;
  $sql_a = "UPDATE user SET username='$name' WHERE tellnumber='$tell'";
}


if ($tell && $val) {

  if ($arr==1) {
    $res["status"] = false;
    $res["mag"] = "已被注册";
  } else {
    $a = mysqli_query($con, $sql_a);
    if ($sql_b) {
      $b = mysqli_query($con, $sql_b);
    }
    if ($a > 0) {
      $res["status"] = true;
      $res["mag"] = "账号已成功修改";
    } else {
      $res["status"] = false;
      $res["mag"] = "数据库错误";
    }
  }
} else {
  $res["status"] = false;
  $res["mag"] = "前端数据错误";
}
echo (json_encode($res, JSON_UNESCAPED_UNICODE));
